;var babiApp = window.babiApp || {};
babiApp = function(){
	return {
		init:function(){
			var _this = this;
      _this.incSlideFun('horizontal','vertical');
      _this.bigImgFun();
      if(_this.isVertical()){
        $("body").addClass('isVertical');
      }else{
        $("body").removeClass('isVertical');
      };
		},
    bigImgFun:function(){

      var swiperV = new Swiper('#swiper-container-big', {
          paginationClickable: true,
          direction: 'horizontal',
          spaceBetween: 50
      });

      $('.zdppjs_main').on('click','span',function(){
          var $this = $(this),
              _index = $this.index();
              sW = $this.width(),
              sH = $this.height(),
              sX = $this.offset().left,
              sY = $this.offset().top;
          console.log(sW,sH,sX,sY,222222);
          //.animate({"widt":"3rem","height":'2rem'}, 500)
          var bigImg =$('#swiper-container-big').find('.swiper-slide').eq(_index).find('img'),
            bigLeft = $('#swiper-container-big').offset().left;
          bigImg.css({
            "width":sW,
            "height":sH,
            "position":'absolute',
            'left':sX- bigLeft,
            'top':sY - 32
          });
          swiperV.slideTo(_index, 0, true);
          $('#swiper-container-big').css('top','0.47rem');
          setTimeout(function(){
            bigImg.animate({
              "width":'100%',
              "height":'100%',
              "position":'absolute',
              'left':0,
              'top':0
            },500)
          },200);
      });
      $('#swiper-container-big').find('.swiper-slide').on('click','.sBtn',function(){
          var $this = $(this),
              _index = $this.parent('.swiper-slide').index(),
              sImg = $('.zdppjs_main').find('span').eq(_index),
              sW = sImg.width(),
              sH = sImg.height(),
              sX = sImg.offset().left,
              sY = sImg.offset().top;
          var bigLeft = $('#swiper-container-big').offset().left,
              bigTop = $('#swiper-container-big').offset().top;
          console.log(sImg.attr('data-num'));
          console.log(sW,sH,sX,sY,333333,_index);

          $this.siblings('img').animate({
              "width":sW,
              "height":sH,
              "position":'fixed',
              'left':sX-bigLeft,
              'top':sY-32
            },500,function(){
                swiperV.slideTo(0, 0, true);
                $('#swiper-container-big').css('top','-500px');
                $this.siblings('img').css({"width":'100%',"height":'100%',"left":0,"top":0})
            });
      });
    },
		incSlideFun:function(horizontal,vertical){
        var  _this = this;
        var mySwiperB = new Swiper ('#swiper-container-two', {
          direction : horizontal,
          pagination: '',
          //virtualTranslate : true,
          mousewheelControl : true,
          preventLinksPropagation : false,
          onInit: function(swiper){
           swiperAnimateCache(swiper);
           swiperAnimate(swiper);
          },
          prevButton:'.swiper-button-prev',
          nextButton:'.swiper-button-next',
          onSlideChangeEnd: function(swiper){
            
            swiperAnimate(swiper);
            if(swiper.activeIndex == 5){
              $('.swiper-button-prev').hide();
              $('.swiper-button-next').hide();
            }else{
              $('.swiper-button-prev').show();
              $('.swiper-button-next').show();
            }
            if(swiper.activeIndex >=0){
                $('.menu-btn').show();
            }else{
              $('.menu-btn').hide();
            };
            //if(swiper.activeIndex <=4){
            //  _this.ajaxSendPageData(6);
            //}else{
            //  _this.ajaxSendPageData(7);
            //};
          },
          onTransitionEnd: function(swiper){
            swiperAnimate(swiper);
          },
          touchMoveStopPropagation : true,
          // watchSlidesProgress: true,
          onProgress: function(swiper){
              for (var i = 0; i < swiper.slides.length; i++){
                var slide = swiper.slides[i];
                var progress = slide.progress;
                var translate = progress*swiper.height/4;  
                scale = 1 - Math.min(Math.abs(progress * 0.5), 1);
                var opacity = 1 - Math.min(Math.abs(progress/2),0.5);
                slide.style.opacity = opacity;
                es = slide.style;
                es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = 'translate3d(0,'+translate+'px,-'+translate+'px) scaleY(' + scale + ')';

              }
          },
          onSetTransition: function(swiper, speed) {
              for (var i = 0; i < swiper.slides.length; i++){
                es = swiper.slides[i].style;
                es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = speed + 'ms';

              }
          }
        });

      var mySwiperA = new Swiper ('#swiper-container-one', {
          direction : vertical,
          pagination: '',
          //virtualTranslate : true,
          mousewheelControl : true,
          preventLinksPropagation : false,
          onInit: function(swiper){
           swiperAnimateCache(swiper);
           swiperAnimate(swiper);
          },
          onSlideChangeEnd: function(swiper){
              switch(swiper.activeIndex){
                  case 2:
                      _this.ajaxSendPageData(1);
                      break;
                  case 3:
                      _this.ajaxSendPageData(2);
                      break;
                  case 4:
                      _this.ajaxSendPageData(3);
                      break;
                  case 5:
                      _this.ajaxSendPageData(4);
                      break;
                  case 6:
                      _this.ajaxSendPageData(5);
                      break;
                  case 7:
                      _this.ajaxSendPageData(6);
                      break;
                  default:
                      index = 0;
                      break;
              };
            if(swiper.activeIndex >=2){
                $('.menu-btn').show();
            }else{
              $('.menu-btn').hide();
            };
            swiperAnimate(swiper);
          },
          onTransitionEnd: function(swiper){
            swiperAnimate(swiper);
          },
          touchMoveStopPropagation : true,
          // watchSlidesProgress: true,
          onProgress: function(swiper){
              for (var i = 0; i < swiper.slides.length; i++){
                var slide = swiper.slides[i];
                var progress = slide.progress;
                var translate = progress*swiper.height/4;  
                scale = 1 - Math.min(Math.abs(progress * 0.5), 1);
                var opacity = 1 - Math.min(Math.abs(progress/2),0.5);
                slide.style.opacity = opacity;
                es = slide.style;
                es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = 'translate3d(0,'+translate+'px,-'+translate+'px) scaleY(' + scale + ')';

              }
          },
          onSetTransition: function(swiper, speed) {
              for (var i = 0; i < swiper.slides.length; i++){
                es = swiper.slides[i].style;
                es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = speed + 'ms';

              }
          }
        });
      $('#imgBtn').on('click',function(){
        $('#swiper-container-one').css({'z-index':"0"});
        $('#swiper-container-two').css({'z-index':"1"});
      })
      $('#menuListBtn').on('click',function(){
        $('#cateList').show();
        $('#menuListBtn').hide();
        $('#swiper-container-one').css({'z-index':"1"});
        $('#swiper-container-two').css({'z-index':"0"});
        $('#swiper-container-big').css('top','-500px');
        mySwiperA.slideTo(1, 500, true);
      });
      $('#cateList').on('click','li',function(){
        var _index = $(this).index();
        $('#menuListBtn').show();
        if(_index <=4){
          $('#swiper-container-one').css({'z-index':"1"});
          $('#swiper-container-two').css({'z-index':"0"});
          mySwiperA.slideTo((_index+2), 500, true);
        }else{
          $('#swiper-container-one').css({'z-index':"0"});
          $('#swiper-container-two').css({'z-index':"1"});
          mySwiperB.slideTo(5, 500, true);
        };
      });

		},
    ajaxSendPageData:function(index){
        var typeData = 'babi',
            pageData = index;
        $.post("http://duoduojf.com/meitai/index.php/wechat/setread", {type: typeData, page: pageData});
    },
		isVertical:function(){
			var w = $(window).width(),
          h = $(window).height();
      if(w < h){
        $('#page').width(h);
        $('#page').height(w);
        return true;
      }else{
        $('#page').width(w);
        $('#page').height(h);
      }
      return false;
		},
    lodingFun:function(){

      var _rootPic = window.winPath,
          _this = this,
          one = 0;

      var picArr = [_rootPic+"/img/sc_a_b.png",_rootPic+"/img/sc_a_d.png",_rootPic+"/img/left_btn.png",_rootPic+"/img/right_btn.png", _rootPic+"/img/sc_a_a.png", _rootPic+"/img/sc_a_c.png", _rootPic+"/img/sc_b_a.png", _rootPic+"/img/sc_b_b_1.png", _rootPic+"/img/sc_b_b_2.png", _rootPic+"/img/sc_b_b_3.png", _rootPic+"/img/sc_b_b_4.png", _rootPic+"/img/sc_b_b_5.png", _rootPic+"/img/sc_b_b_6.png", _rootPic+"/img/sc_c_a.png", _rootPic+"/img/sc_c_b.png", _rootPic+"/img/sc_d_b.png", _rootPic+"/img/sc_d_a.png", _rootPic+"/img/sc_e_a.png", _rootPic+"/img/ppjs_a_00.jpg", _rootPic+"/img/ppjs_a_01.jpg", _rootPic+"/img/ppjs_a_02.jpg", _rootPic+"/img/ppjs_a_03.jpg", _rootPic+"/img/ppjs_a_04.jpg", _rootPic+"/img/ppjs_a_05.jpg", _rootPic+"/img/ppjs_a_06.jpg", _rootPic+"/img/ppjs_a_07.jpg", _rootPic+"/img/ppjs_a_08.jpg", _rootPic+"/img/ppjs_a_09.jpg", _rootPic+"/img/sc_e_b.png", _rootPic+"/img/sc_f_b.png", _rootPic+"/img/sc_f_a.png", _rootPic+"/img/sc_g_c.png", _rootPic+"/img/sc_g_a.png", _rootPic+"/img/sc_g_b.png", _rootPic+"/img/xsjq_01.jpg", _rootPic+"/img/xsjq_02.jpg", _rootPic+"/img/xsjq_03.jpg", _rootPic+"/img/xsjq_04.jpg", _rootPic+"/img/xsjq_05.jpg", _rootPic+"/img/sc_h_b.png", _rootPic+"/img/sc_h_a.png", _rootPic+"/img/ppjs_00.jpg", _rootPic+"/img/ppjs_01.jpg", _rootPic+"/img/ppjs_02.jpg", _rootPic+"/img/ppjs_03.jpg", _rootPic+"/img/ppjs_04.jpg", _rootPic+"/img/ppjs_05.jpg", _rootPic+"/img/ppjs_06.jpg", _rootPic+"/img/ppjs_07.jpg", _rootPic+"/img/ppjs_08.jpg", _rootPic+"/img/ppjs_09.jpg", _rootPic+"/img/ppjs_10.jpg"];
      var imgNum = 0;
        $.imgpreload(picArr,{
          each: function(){
            var status = $(this).data('loaded') ? 'success' : 'error';
            if (status == "success") {                
                var v = (parseFloat(++imgNum) / picArr.length).toFixed(2);
                $("#loding .jindu").html(Math.round(v * 100) + "%");
            }
          },
          all: function(){
            if(!_this.isVertical()){
              $('#loding').hide();
              _this.init();
            };
          }
        });
    },
    //login
    loginFun:function(){
      var _this = this;
      if(_this.isVertical()){
        $("body").addClass('isVertical');
        $('#comLoding').show();
      }else{
        $("body").removeClass('isVertical');
        $('#comLoding').hide();
      };
      var _rootPic = window.winPath,
          _this = this;
      var picArr = [
          _rootPic+"/img/list_loding_icon.png",
          _rootPic+"/img/list_loding_text.png",
          _rootPic+"/img/login_icon.png",
          _rootPic+"/img/login_pass_icon.png", 
          _rootPic+"/img/login_user_icon.png", 
          _rootPic+"/img/login_bg1.png"
          ]
      var imgNum = 0;
        $.imgpreload(picArr,{
          each: function(){
            var status = $(this).data('loaded') ? 'success' : 'error';
            if (status == "success") {                
                var v = (parseFloat(++imgNum) / picArr.length).toFixed(2);
                $("#comLoding .jindu").html(Math.round(v * 100) + "%");
            }
          },
          all: function(){
            if(!_this.isVertical()){
              $('#comLoding').hide();
            };
          }
        });
        $('.submit-con').on('click','a',function(){
          var userName = $('#userName').val(),
              password = $('#password').val();
          if(userName == "" || password == ""){
            alert('用户名或密码不能为空！');
            return false;
          };
          if(!$('#checkId').is(':checked')){
            alert('请仔细阅读保密条款！');
            return false;
          };
            $.post(action_site,{username:userName,password:password},function(d){
               if (d.code==1) {
                   window.location.href = d.data.url;
               }else {
                   alert(d.msg);
                   return false;
               }
            },'json');
        });
    },
    // password
    passWordFun:function(){
      var _this = this;
      $('.submit-btn').click(function(){
          var _oldpwd = $("#oldPassword").val();
          var _newpwd =   $("#newPassword").val();
          var _renewpwd = $('#confirmPassword').val();
          if (_renewpwd !== _newpwd)
          {
              alert('两次输入新密码不一致');
              return false;
          }
          if (_oldpwd == _newpwd) {
              alert('新旧密码相同');
              return false;
          }
          $.post(action_url,{oldpassword:_oldpwd,newpassword:_newpwd}, function (d) {
                if (d.code==1) {
                    alert(d.msg);
                    window.history.back(-1);
                }else {
                    alert(d.msg);
                    return false;
                }
          },'json');
      });
    },
    //list
    listFun:function(){
      var _this = this;
      if(_this.isVertical()){
        $("body").addClass('isVertical');
        $('#comLoding').show();
      }else{
        $("body").removeClass('isVertical');
        $('#comLoding').hide();
      };

      var _rootPic = window.winPath,
          _this = this;
      var picArr = [
          _rootPic+"/img/list_loding_icon.png",
          _rootPic+"/img/list_loding_text.png",
          _rootPic+"/img/list_sty_01.png",
          _rootPic+"/img/list_sty_02.png", 
          _rootPic+"/img/list_sty_03.png", 
          _rootPic+"/img/list_sty_04.png", 
          _rootPic+"/img/list_state_icon1.png", 
          _rootPic+"/img/list_state_icon2.png", 
          _rootPic+"/img/list_state_icon3.png", 
          _rootPic+"/img/list_state_icon4.png", 
          _rootPic+"/img/list_state_icon5.png", 
          _rootPic+"/img/list_left_arr.png", 
          _rootPic+"/img/list_right_arr.png", 
          _rootPic+"/img/list_img_01.png", 
          _rootPic+"/img/list_img_02.png", 
          _rootPic+"/img/list_img_03.png", 
          _rootPic+"/img/list_img_04.png", 
          _rootPic+"/img/list_img_05.png", 
          _rootPic+"/img/list_img_01.png", 
          _rootPic+"/img/list_img_06.png", 
          _rootPic+"/img/list_img_06.png", 
          _rootPic+"/img/list_nav_back_icon.png", 
          _rootPic+"/img/list_bg.png", 
          _rootPic+"/img/list_nav_out_icon.png"
          ]
      var imgNum = 0;
        $.imgpreload(picArr,{
          each: function(){
            var status = $(this).data('loaded') ? 'success' : 'error';
            if (status == "success") {                
                var v = (parseFloat(++imgNum) / picArr.length).toFixed(2);
                $("#comLoding .jindu").html(Math.round(v * 100) + "%");
            }
          },
          all: function(){
            if(!_this.isVertical()){
              $('#comLoding').hide();
            };
          }
        });

      var swiper = new Swiper('.swiper-container', {
        slidesPerView: 3,
        paginationClickable: true,
        spaceBetween: 10,
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
    });
    },
    subjectFun:function(){
      var _this = this;
      if(_this.isVertical()){
        $("body").addClass('isVertical');
        $('#comLoding').show();
      }else{
        $("body").removeClass('isVertical');
        $('#comLoding').hide();
      };

      var _rootPic = window.winPath,
          _this = this;
      var picArr = [
          _rootPic+"/img/list_loding_icon.png",
          _rootPic+"/img/list_loding_text.png",
          _rootPic+"/img/list_adopt_icon.png", 
          _rootPic+"/img/list_check_icon.png", 
          _rootPic+"/img/list_checked_icon.png", 
          _rootPic+"/img/list_nav_back_icon.png", 
          _rootPic+"/img/list_nav_out_icon.png", 
          _rootPic+"/img/list_error_icon.png", 
          _rootPic+"/img/list_no_adopt_icon.png", 
          _rootPic+"/img/list_right_icon.png", 
          _rootPic+"/img/list_scoll.png", 
          ]
      var imgNum = 0;
        $.imgpreload(picArr,{
          each: function(){
            var status = $(this).data('loaded') ? 'success' : 'error';
            if (status == "success") {                
                var v = (parseFloat(++imgNum) / picArr.length).toFixed(2);
                $("#comLoding .jindu").html(Math.round(v * 100) + "%");
            }
          },
          all: function(){
            if(!_this.isVertical()){
              $('#comLoding').hide();
            };
          }
      });

      $('.scroll-pane').jScrollPane();
      $('.scroll-pane').find('.item-con').each(function(index){
          var $this = $(this);
          $this.find('.items').on('click','label',function(){
            var $that = $(this);
              $that.addClass('checked').siblings('label').removeClass('checked');
          });
      });
      $('.submit-btn').on('click',function(){
        var itemLen = 0,
            selectLen = $('.scroll-pane').find('.checked').length,
            aqArr = [],
            errorNum = $('#errorNum').val();
        $('.scroll-pane').find('.item-con').each(function(index){
            var $this = $(this),
                aqObj = {
                  "q":$this.attr('data-a'),
                  'a':($this.find('.items .checked').index()+1) || ""
                };
            aqArr.push(aqObj)
            itemLen++;
        });
        if(selectLen < itemLen){
          alert("请填写所有题目以后再提交！");
          return false;
        };
        for(var i = 0 ; i < aqArr.length; i++){
          if(aqArr[i]["q"] != aqArr[i]["a"]){
            $('.scroll-pane').find('.item-con').eq(i).find('.state_icon').addClass('right_icon').removeClass('error_icon').show();
          }else{
            errorNum ++;
            $('.scroll-pane').find('.item-con').eq(i).find('.state_icon').addClass('error_icon').removeClass('right_icon').show();
          }
        };
          $.post(action_url,{err_num:parseInt(errorNum)},function(d){},'json');
        if(errorNum >0){
            $('.all-state').find('.state_right').hide();
            $('.all-state').find('.state_error').show();
            $('.submit-btn').show();
        }else{
            $('.all-state').find('.state_right').show();
            $('.all-state').find('.state_error').hide();
            $('.submit-btn').hide();
        }
      });
    }
	}
};
function hengshuping(){
  if(window.orientation==180||window.orientation==0){ 
        window.location.reload()
   }
  if(window.orientation==90||window.orientation==-90){ 
        window.location.reload()
    } 
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", hengshuping, false); 
